package com.wysql.common.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ResourceUtils;

import java.io.*;
import java.nio.charset.StandardCharsets;

@Slf4j
public class JsonFileUtils {
    public static String readJsonFile(String fileName) {
        File file;//"classpath:" +
        try {
            file = ResourceUtils.getFile(fileName);
        }catch (IOException e){
            e.printStackTrace();
            return null;
        }
        String jsonStr;
        try (Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)){
            int ch;
            StringBuilder sb = new StringBuilder();
            while ((ch = reader.read()) != -1) {
                sb.append((char) ch);
            }
            jsonStr = sb.toString();
            return jsonStr;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}
